package lab.gene.service.impl;
import java.util.Date;
import java.util.List;

import lab.gene.pojo.Gene;
import lab.gene.pojo.GeneRespotted;
import lab.gene.dao.GeneDAO;
import lab.gene.dao.GeneRespottedDAO;

import lab.gene.service.GeneRespottedService;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GeneRespottedServiceImpl implements GeneRespottedService {

	@Override
	public GeneRespotted getGeneRespottedByNameAndType(String geneName,
			String type) {
		// TODO Auto-generated method stub
		GeneRespotted rs = null;
		GeneRespottedDAO dao = new GeneRespottedDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		rs = dao.getGeneRespottedByNameAndType(g, type);
		return rs;
	}

	@Override
	public void addGeneRespotted(String geneName, String type, String userName, String comments, Date recordDate) {
		// TODO Auto-generated method stub
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GeneRespottedDAO dao = new GeneRespottedDAO();
		GeneRespotted rs = new GeneRespotted();
		rs.setComments(comments);
		rs.setDateModified(new Date());
		rs.setGene(g);
		rs.setRecordDate(recordDate);
		rs.setType(type);
		rs.setUser(u);
		dao.addGeneRespotted(rs);

	}

	@Override
	public List<GeneRespotted> getGeneRespottedHistory(String geneName, String type) {
		List<GeneRespotted> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GeneRespottedDAO dao = new GeneRespottedDAO();
		g = dao.getGeneRespottedHistory(gene, type);
		return g;
	}

}
